USE [BukstorBD]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Libros_Editoriales]') AND parent_object_id = OBJECT_ID(N'[dbo].[Libros]'))
ALTER TABLE [dbo].[Libros] DROP CONSTRAINT [FK_Libros_Editoriales]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Libros_Subcategorias]') AND parent_object_id = OBJECT_ID(N'[dbo].[Libros]'))
ALTER TABLE [dbo].[Libros] DROP CONSTRAINT [FK_Libros_Subcategorias]
GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_Libros_discontinuo]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[Libros] DROP CONSTRAINT [DF_Libros_discontinuo]
END

GO

USE [BukstorBD]
GO

/****** Object:  Table [dbo].[Libros]    Script Date: 09/23/2012 21:21:48 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Libros]') AND type in (N'U'))
DROP TABLE [dbo].[Libros]
GO

USE [BukstorBD]
GO

/****** Object:  Table [dbo].[Libros]    Script Date: 09/23/2012 21:21:48 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Libros](
	[idLibro] [int] IDENTITY(1,1) NOT NULL,
	[isbn] [char](13) NOT NULL,
	[titulo] [nvarchar](50) NOT NULL,
	[idEditorial] [int] NOT NULL,
	[tapa] [varchar](50) NULL,
	[sinopsis] [nvarchar](max) NOT NULL,
	[idSubcategoria] [int] NOT NULL,
	[discontinuo] [bit] NOT NULL,
 CONSTRAINT [PK_Libros] PRIMARY KEY CLUSTERED 
(
	[idLibro] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Nombre del archivo ubicado en la carpeta ~/images/tapas/ que contiene la tapa de este libro' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Libros', @level2type=N'COLUMN',@level2name=N'tapa'
GO

ALTER TABLE [dbo].[Libros]  WITH CHECK ADD  CONSTRAINT [FK_Libros_Editoriales] FOREIGN KEY([idEditorial])
REFERENCES [dbo].[Editoriales] ([idEditorial])
GO

ALTER TABLE [dbo].[Libros] CHECK CONSTRAINT [FK_Libros_Editoriales]
GO

ALTER TABLE [dbo].[Libros]  WITH CHECK ADD  CONSTRAINT [FK_Libros_Subcategorias] FOREIGN KEY([idSubcategoria])
REFERENCES [dbo].[Subcategorias] ([idSubategoria])
GO

ALTER TABLE [dbo].[Libros] CHECK CONSTRAINT [FK_Libros_Subcategorias]
GO

ALTER TABLE [dbo].[Libros] ADD  CONSTRAINT [DF_Libros_discontinuo]  DEFAULT ((0)) FOR [discontinuo]
GO

